<%--
  Created by IntelliJ IDEA.
  User: 肖
  Date: 2020/10/6
  Time: 23:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<div class="row">
    <div class="col-md-5" style="float: right;">
        <form class="bs-example bs-example-form" role="form">
            <div class="input-group">
                <input type="text" id='sellersearch' class="form-control"  placeholder="请输入" value="${search}">
                <span class="input-group-btn">
                            <button type="button" id="sellerbutton" class="btn btn-primary">
                                <span class="glyphicon glyphicon-search"></span>&nbsp搜索
                            </button>
                            </span>
            </div>
        </form>
    </div>


</div>
<div class="row" style="margin-top: 10px;">
    <div class="col-md-6">
        <button id="sellers" type="button" class="btn btn-primary btn-sm">
            <span class="glyphicon glyphicon-refresh"></span>刷新
        </button>
        <button id="moredelseller"  type="button" class="btn btn-danger btn-sm">
            <span class=" glyphicon glyphicon-trash"></span>批量删除
        </button>

    </div>
</div>

<div class="tab-pane fade in active" >
    <table class="table table-hover table-responsive">

        <thead>
        <tr>
            <th><input id="ck_all_seller" type="checkbox"></th>
            <th>销售人员ID</th>
            <th>姓名</th>
            <th>电话</th>
            <th>账号</th>
            <th>密码</th>
            <th>预约时间</th>
            <th>销售额</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${page.list}" var="p" varStatus="vs">
            <tr>
                <th><input value="${p.sid}" name="ck_content_seller" type="checkbox"></th>

                <th>${p.sid}</th>
                <th ondblclick='update_selleruname(this,${p.sid})'>${p.uname}</th>
                <th ondblclick='update_sellerphone(this,${p.sid})'>${p.phone}</th>
                <th ondblclick='update_selleraccount(this,${p.sid})'>${p.account}</th>
                <th ondblclick='update_sellerpwd(this,${p.sid})'>${p.pwd}</th>

                <th ondblclick='update_sellerresDate(this,${p.sid})'><fmt:formatDate value='${p.resDate}' pattern='yyyy-MM-dd' /></th>
                <th ondblclick='update_sellersellerTotal(this,${p.sid})'>${p.sellTotal}</th>

                <td>
                    <a onclick='delseller(this,${p.sid})' class="text-danger" href="#"><span class="glyphicon glyphicon-trash"></span></a>
                        <%--                    <a class="text-warning" href="#"><span class="glyphicon glyphicon-edit"></span></a>--%>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<script src="<%=request.getContextPath()%>/plugins/jquery/jquery.min.js"></script>
<script src="<%=request.getContextPath()%>/plugins/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>


<script>

    //批量删除start

    //批量删除start
    $(function(){
        let ck = document.getElementById("ck_all_seller");
        let cks = document.getElementsByName("ck_content_seller");
        ck.onclick=function(){
            if(ck.checked){
                for(let i=0;i<cks.length;i++){
                    cks[i].checked=true;
                }
            }else{
                for(let i=0;i<cks.length;i++){
                    cks[i].checked=false;
                }
            }
        }
    });
    $(function(){

        document.getElementById("moredelseller").onclick=function(){
            let cks = document.getElementsByName("ck_content_seller");
            let count = 0;
            for(let i=0;i<cks.length;i++){
                if(cks[i].checked){
                    count++;
                }
            }
            if(count==0){
                alert("sorry,请你先选中!");
                return;
            }
            let flag = confirm("确定删除吗?");
            if(flag){
                let sids = "";
                for(let i=0;i<cks.length;i++){
                    if(cks[i].checked){
                        sids+=cks[i].value+":";
                    }
                }
                $.post('/prj/admin/delAllseller',{"sid":sids},function(data){
                    if(data.code=="200"){
                        $("#one").load("/prj/admin/two");
                    }
                })

            }
        };
    });

    //异步刷新
    $("#sellers").click(function () {

        $("#two").load("/prj/admin/two",{});
    })
    //全局搜索
    $("#sellerbutton").click(function () {
        let search = $("#sellersearch").val();
        $("#two").load("/prj/admin/two",{search:search});
    })

    //异步删除
    function delseller(obj,id){
        $.post('/prj/admin/delseller',{"id":id},function(data){
            if(data.code=="200"){
                let tr = obj.parentElement.parentElement;
                $(tr).remove();

            }
        })
    }



    //修改开始
    //修改销售人员
    function update_selleruname(obj,id){
        let str = "<input onblur='update_input_selleruname(this,"+id+")' type='text' value='"+obj.innerText+"'>";
        obj.innerHTML = str;
    }
    function update_input_selleruname(obj,id){
        $.post('/prj/admin/update',{"uname":obj.value,"sid":id},function(data){
            if(data.code=="200"){
                obj.parentElement.innerText=obj.value;
            }
        })
    }
    //修改销售人员phone
    function update_sellerphone(obj,id){
        let str = "<input onblur='update_input_sellerphone(this,"+id+")' type='text' value='"+obj.innerText+"'>";
        obj.innerHTML = str;
    }
    function update_input_sellerphone(obj,id){
        $.post('/prj/admin/update',{"phone":obj.value,"sid":id},function(data){
            if(data.code=="200"){
                obj.parentElement.innerText=obj.value;
            }
        })
    }
    //修改销售人员账号
    function update_selleraccount(obj,id){
        let str = "<input onblur='update_input_selleraccount(this,"+id+")' type='text' value='"+obj.innerText+"'>";
        obj.innerHTML = str;
    }
    function update_input_selleraccount(obj,id){
        $.post('/prj/admin/update',{"account":obj.value,"sid":id},function(data){
            if(data.code=="200"){
                obj.parentElement.innerText=obj.value;
            }
        })
    }

    //修改销售人员密码
    function update_sellerpwd(obj,id){
        let str = "<input onblur='update_input_sellerpwd(this,"+id+")' type='text' value='"+obj.innerText+"'>";
        obj.innerHTML = str;
    }
    function update_input_sellerpwd(obj,id){
        $.post('/prj/admin/update',{"pwd":obj.value,"sid":id},function(data){
            if(data.code=="200"){
                obj.parentElement.innerText=obj.value;
            }
        })
    }

    //修改销售人员预约时间
    function update_sellerresDate(obj,id){
        let str = "<input onblur='update_input_sellerresDate(this,"+id+")' type='text' value='"+obj.innerText+"'>";
        obj.innerHTML = str;
    }
    function update_input_sellerresDate(obj,id){
        $.post('/prj/admin/update',{"resDate":obj.value,"sid":id},function(data){
            if(data.code=="200"){
                obj.parentElement.innerText=obj.value;
            }
        })
    }

    //修改销售人员的销售额
    function update_sellersellerTotal(obj,id){
        let str = "<input onblur='update_input_sellersellTotal(this,"+id+")' type='text' value='"+obj.innerText+"'>";
        obj.innerHTML = str;
    }
    function update_input_sellersellTotal(obj,id){
        $.post('/prj/admin/update',{"sellTotal":obj.value,"sid":id},function(data){
            if(data.code=="200"){
                obj.parentElement.innerText=obj.value;
            }
        })
    }








</script>
<%@include file="../page/adminsellerpage.jsp" %>